package com.zx.auth.block.mapstruct;

import com.zx.auth.block.modle.OAuth2AuthorizationConsent;
import com.zx.auth.block.vo.OAuth2AuthorizationConsentVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;
import org.mapstruct.factory.Mappers;

/**
 * <p>
 * description: OAuth2授权同意MapStruct映射器 <br>
 * create: 2025-11-12 16:10
 * </p>
 *
 * @author
 */
@Mapper(unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface OAuth2AuthorizationConsentMapStructMapper {
    OAuth2AuthorizationConsentMapStructMapper INSTANCE = Mappers.getMapper(OAuth2AuthorizationConsentMapStructMapper.class);

    /**
     * 将OAuth2AuthorizationConsent实体转换为OAuth2AuthorizationConsentVO视图对象
     *
     * @param consent 授权同意实体
     * @return OAuth2AuthorizationConsentVO视图对象
     */
    OAuth2AuthorizationConsentVO consentToConsentVO(OAuth2AuthorizationConsent consent);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param consent   授权同意实体
     * @param consentVO 授权同意VO
     */
    @AfterMapping
    default void setDescriptions(OAuth2AuthorizationConsent consent, @MappingTarget OAuth2AuthorizationConsentVO consentVO) {
        // 可以在这里设置额外的描述性字段
        // 例如通过客户端ID查询客户端名称等
        if (consentVO.getClientName() == null) {
            consentVO.setClientName("未知客户端");
        }
    }
}